Moving modules by looping through the whole project don't work :o(

Hello,

I got a small script which shall move all module to the projects root. But this script doesn't work always. Sometimes it does, sometimes it does not.

The code looks like this:
 

void MoveModules(void)
{
    Item   item_move
    string str_modName       = ""
    string str_modName_short = ""
 
 
    outstream  = append str_file
    outstream  <<"The following modules were moved to the project root for import\nModule;State"
    close outstream
 
    current = folder "/"str_project_new"/"            //set current folder to root (str_project_new is global)
 
    Folder ProjectRoot = current
 
    for item_move in current Project do
    {
        if (type(item_move) == "Formal")
        {
            string str_error  = ""
           
            str_modName       = fullName(item_move)
            str_modName_short = name(item_move)
            str_error         = move(item_move, ProjectRoot)
           
            outstream  = append str_file
            outstream << "\n"str_modName_short";"
           
            if (str_error != "")
            {
                outstream << "ERROR: "str_error""
                error_move_modules = true
            }
            else
            {
               outstream << "OK"
               int_moved++
            }
            close outstream
        }
    }
    return
}


It works for some modules (sometimes one, sometimes three or even ten), than the execution halts with the error:

-R-E- DXL: <Line:49> An unexpected error has occurred.

Line 49 is:

 

for item_move in current Project do



Does anyone has any idea what this might be?



 


Senseo - Mon Dec 07 07:39:02 EST 2009

The error Message
Senseo - Mon Dec 07 07:40:27 EST 2009

Sometimes (not always), a Diagnostic Log of DOORS appears:

DOORS: **** Translating a structured exception ****
DOORS: Version DOORS 7.1, build number 71173, built on Jul 30 2007 10:47:46.
DOORS: Whistler Service Pack 2 (Build 2600)

DOORS: DOORS: 41 percent of memory is in use.
DOORS: There are 2096492 total Kbytes of physical memory.
DOORS: There are 1227132 free Kbytes of physical memory.
DOORS: There are 2200200 total Kbytes of paging file.
DOORS: There are 1408924 free Kbytes of paging file.
DOORS: There are 1fff80 total Kbytes of virtual memory.
DOORS: There are 1e47dc free Kbytes of virtual memory.

DOORS: argv[0]: C:\Program Files\Telelogic\DOORS 7.1\bin\doors.exe
DOORS: argv[1]: -user
DOORS: argv[2]: YYYY
DOORS: argv[3]: -password
DOORS: argv[4]: XXXX
DOORS: doors.exe caused an EXCEPTION_ACCESS_VIOLATION in module <UNKNOWN> at 001B:01F31D62
DOORS: Stack trace string not available
DOORS: 001B:007096E9 (0x03CD6EC0 0x00000000 0x03CE12B0 0x01379E50) doors.exe
DOORS: 001B:0070A2A1 (0x03CD7534 0x00000000 0x03CD77D0 0x01379E50) doors.exe
DOORS: 001B:0070FC47 (0x03CDF280 0x00000001 0x01F3F3B0 0x004C4795) doors.exe
DOORS: 001B:0070FB62 (0x01341500 0x03CD2D30 0x0012F93C 0x00000000) doors.exe
DOORS: 001B:004FCC89 (0x01F0B320 0x7E41945D 0x01F0BBD0 0x00000111) doors.exe
DOORS: 001B:00632B9E (0x01F0BBD0 0x000008A6 0x000E0BE8 0x0012FA38) doors.exe
DOORS: 001B:00632F92 (0x05F00AAA 0x00000111 0x000008A6 0x000E0BE8) doors.exe
DOORS: 001B:0062E694 (0x0062E67F 0x05F00AAA 0x00000111 0x000008A6) doors.exe
DOORS: 001B:7E418816 (0x00000000 0x0062E67F 0x05F00AAA 0x00000111) USER32.dll
DOORS: 001B:7E41B89B (0x00E5BF20 0x00EC59D8 0x000008A6 0x000E0BE8) USER32.dll
DOORS: 001B:7E41B903 (0x05F00AAA 0x00000111 0x000008A6 0x000E0BE8) USER32.dll
DOORS: 001B:7E44FD1D (0x00EFA378 0x00000000 0x00EFA378 0x001C5308) USER32.dll
DOORS: 001B:7E446561 (0x001C5308 0x00000001 0x00000000 0x0012FC00) USER32.dll
DOORS: 001B:7E426DF4 (0x00EFA378 0x00000202 0x00000000 0x0006003A) USER32.dll
DOORS: 001B:7E43B04A (0x000E0BE8 0x00000202 0x00000000 0x0006003A) USER32.dll
DOORS: 001B:7E418734 (0x7E43AFFE 0x000E0BE8 0x00000202 0x00000000) USER32.dll
DOORS: 001B:7E418816 (0x00000000 0x7E43AFFE 0x000E0BE8 0x00000202) USER32.dll
DOORS: 001B:7E41C63F (0x7E43AFFE 0x000E0BE8 0x00000202 0x00000000) USER32.dll
DOORS: 001B:7E41F65D (0x7E43AFFE 0x000E0BE8 0x00000202 0x00000000) USER32.dll
DOORS: 001B:00635C0D (0x000E0BE8 0x00000202 0x00000000 0x0006003A) doors.exe
DOORS: 001B:00635C99 (0x00635C7C 0x000E0BE8 0x00000202 0x00000000) doors.exe
DOORS: 001B:7E418816 (0x00000000 0x00635C7C 0x000E0BE8 0x00000202) USER32.dll
DOORS: 001B:7E4189CD (0x0012FDD4 0x00000001 0x0012FDF0 0x0062F5F6) USER32.dll
DOORS: 001B:7E4196C7 (0x0012FDD4 0x000000B0 0x00000001 0x00000000) USER32.dll
DOORS: 001B:0062F5F6 (0x000000B0 0x00000001 0x00000000 0x01EA4E91) doors.exe
DOORS: 001B:00459766 (0x00400000 0x00000000 0x001423C5 0x00000001) doors.exe
DOORS: 001B:0045A6EE (0x00400000 0x00000000 0x001423C5 0x00000001) doors.exe
DOORS: 001B:00407E7B (0x000000B0 0x003A0043 0x7FFDD000 0x8054A6ED) doors.exe
DOORS: 001B:7C816FE7 (0x00407D9B 0x00000000 0x78746341 0x00000020) kernel32.dll
DOORS: **** end of event ****

Re: The error Message
Peter_Albert - Mon Dec 07 08:00:57 EST 2009

Senseo - Mon Dec 07 07:40:27 EST 2009
Sometimes (not always), a Diagnostic Log of DOORS appears:

DOORS: **** Translating a structured exception ****
DOORS: Version DOORS 7.1, build number 71173, built on Jul 30 2007 10:47:46.
DOORS: Whistler Service Pack 2 (Build 2600)

DOORS: DOORS: 41 percent of memory is in use.
DOORS: There are 2096492 total Kbytes of physical memory.
DOORS: There are 1227132 free Kbytes of physical memory.
DOORS: There are 2200200 total Kbytes of paging file.
DOORS: There are 1408924 free Kbytes of paging file.
DOORS: There are 1fff80 total Kbytes of virtual memory.
DOORS: There are 1e47dc free Kbytes of virtual memory.

DOORS: argv[0]: C:\Program Files\Telelogic\DOORS 7.1\bin\doors.exe
DOORS: argv[1]: -user
DOORS: argv[2]: YYYY
DOORS: argv[3]: -password
DOORS: argv[4]: XXXX
DOORS: doors.exe caused an EXCEPTION_ACCESS_VIOLATION in module <UNKNOWN> at 001B:01F31D62
DOORS: Stack trace string not available
DOORS: 001B:007096E9 (0x03CD6EC0 0x00000000 0x03CE12B0 0x01379E50) doors.exe
DOORS: 001B:0070A2A1 (0x03CD7534 0x00000000 0x03CD77D0 0x01379E50) doors.exe
DOORS: 001B:0070FC47 (0x03CDF280 0x00000001 0x01F3F3B0 0x004C4795) doors.exe
DOORS: 001B:0070FB62 (0x01341500 0x03CD2D30 0x0012F93C 0x00000000) doors.exe
DOORS: 001B:004FCC89 (0x01F0B320 0x7E41945D 0x01F0BBD0 0x00000111) doors.exe
DOORS: 001B:00632B9E (0x01F0BBD0 0x000008A6 0x000E0BE8 0x0012FA38) doors.exe
DOORS: 001B:00632F92 (0x05F00AAA 0x00000111 0x000008A6 0x000E0BE8) doors.exe
DOORS: 001B:0062E694 (0x0062E67F 0x05F00AAA 0x00000111 0x000008A6) doors.exe
DOORS: 001B:7E418816 (0x00000000 0x0062E67F 0x05F00AAA 0x00000111) USER32.dll
DOORS: 001B:7E41B89B (0x00E5BF20 0x00EC59D8 0x000008A6 0x000E0BE8) USER32.dll
DOORS: 001B:7E41B903 (0x05F00AAA 0x00000111 0x000008A6 0x000E0BE8) USER32.dll
DOORS: 001B:7E44FD1D (0x00EFA378 0x00000000 0x00EFA378 0x001C5308) USER32.dll
DOORS: 001B:7E446561 (0x001C5308 0x00000001 0x00000000 0x0012FC00) USER32.dll
DOORS: 001B:7E426DF4 (0x00EFA378 0x00000202 0x00000000 0x0006003A) USER32.dll
DOORS: 001B:7E43B04A (0x000E0BE8 0x00000202 0x00000000 0x0006003A) USER32.dll
DOORS: 001B:7E418734 (0x7E43AFFE 0x000E0BE8 0x00000202 0x00000000) USER32.dll
DOORS: 001B:7E418816 (0x00000000 0x7E43AFFE 0x000E0BE8 0x00000202) USER32.dll
DOORS: 001B:7E41C63F (0x7E43AFFE 0x000E0BE8 0x00000202 0x00000000) USER32.dll
DOORS: 001B:7E41F65D (0x7E43AFFE 0x000E0BE8 0x00000202 0x00000000) USER32.dll
DOORS: 001B:00635C0D (0x000E0BE8 0x00000202 0x00000000 0x0006003A) doors.exe
DOORS: 001B:00635C99 (0x00635C7C 0x000E0BE8 0x00000202 0x00000000) doors.exe
DOORS: 001B:7E418816 (0x00000000 0x00635C7C 0x000E0BE8 0x00000202) USER32.dll
DOORS: 001B:7E4189CD (0x0012FDD4 0x00000001 0x0012FDF0 0x0062F5F6) USER32.dll
DOORS: 001B:7E4196C7 (0x0012FDD4 0x000000B0 0x00000001 0x00000000) USER32.dll
DOORS: 001B:0062F5F6 (0x000000B0 0x00000001 0x00000000 0x01EA4E91) doors.exe
DOORS: 001B:00459766 (0x00400000 0x00000000 0x001423C5 0x00000001) doors.exe
DOORS: 001B:0045A6EE (0x00400000 0x00000000 0x001423C5 0x00000001) doors.exe
DOORS: 001B:00407E7B (0x000000B0 0x003A0043 0x7FFDD000 0x8054A6ED) doors.exe
DOORS: 001B:7C816FE7 (0x00407D9B 0x00000000 0x78746341 0x00000020) kernel32.dll
DOORS: **** end of event ****

It is generally a very bad idea to modify in any way the items over which you run a for loop. This is true for modules, views, attributes, etc.. The typical solution is to first fill a Skip list during the for loop, and in the second stept loop over the skip list and perform the action on the elements of the Skip list (or better store the fullNames of the modules and use the 'item' perm to get a handle on the items again when looping over the SKip list).

Regards,

Peter

Re: The error Message
Senseo - Mon Dec 07 08:58:09 EST 2009

Peter_Albert - Mon Dec 07 08:00:57 EST 2009
It is generally a very bad idea to modify in any way the items over which you run a for loop. This is true for modules, views, attributes, etc.. The typical solution is to first fill a Skip list during the for loop, and in the second stept loop over the skip list and perform the action on the elements of the Skip list (or better store the fullNames of the modules and use the 'item' perm to get a handle on the items again when looping over the SKip list).

Regards,

Peter

Hello Peter,

you arguments sound right. I tried to realize it with such a skip-list but I don't get it. I never used it before.
Do you have an example for me how it might work?

Re: The error Message
Peter_Albert - Mon Dec 07 09:50:49 EST 2009

Senseo - Mon Dec 07 08:58:09 EST 2009
Hello Peter,

you arguments sound right. I tried to realize it with such a skip-list but I don't get it. I never used it before.
Do you have an example for me how it might work?

This should het you started

Skip itemList = createString()
string itemName
Item currItem
 
for currItem in current Folder do
{ // Loop through current folder
    if (type(currItem) == "Formal")
        { // Store formal modules
                itemName = fullName currItem
                put(itemList, itemName, itemName)
        } // Store formal modules
} // Loop through current folder
 
for itemName in itemList do
{ // Loop through the item list
        currItem = item(itemName)
        // Do something with the item here
        print (name currItem) "\n" 
} // Loop through the item list
 
delete itemList

 


Peter

 

Re: The error Message
Senseo - Mon Dec 07 10:23:31 EST 2009

Peter_Albert - Mon Dec 07 09:50:49 EST 2009

This should het you started

Skip itemList = createString()
string itemName
Item currItem
 
for currItem in current Folder do
{ // Loop through current folder
    if (type(currItem) == "Formal")
        { // Store formal modules
                itemName = fullName currItem
                put(itemList, itemName, itemName)
        } // Store formal modules
} // Loop through current folder
 
for itemName in itemList do
{ // Loop through the item list
        currItem = item(itemName)
        // Do something with the item here
        print (name currItem) "\n" 
} // Loop through the item list
 
delete itemList

 


Peter

 

Hi Peter,

thank you very much. It worked.

I now tried to modify the code a little bit:

put(itemList, itemName, itemPath)

Am I right that I know created a struct like this:

itemList{
Module1 - Folder1
Module2 - Folder2
Module3 - Folder2
...
}

For understanding I want to move the modules to one folder and than back. But I don't get it. How can I access this? I'm really confused about the DXL-manual from Telelogic.

Re: Moving modules by looping through the whole project don't work :o(
llandale - Mon Dec 07 18:10:52 EST 2009

Albert is right. Don't change anything in native loops, stage them in a Skip list first.

However. You may perhaps want to process the items in the same order as encountered. If so:

Skip  skpProjItems = create()  // KEY: 'int' Sequence; DATA: 'Item' item handle
int   Sequencer = 0
for item_move in current Project do
{  put(skpProjItems, Sequencer++, item_move)
}
 
for item_move in skpProjItems do
{  deal with this item
}
delete(skpProjItems)

 


If you want to deal with them in alpha order, determine the string 'name' of the item and insert that as the 1st parameter Key; but first use 'createString' for Skips with key 'string'.

Notice that the loop for the Skip list is the 2nd parameter DATA, not the first parameter KEY. If you want the Key:

 

 

for item_move in skpProjItems do
{  Sequencer = (int key skpProjItems)
   bla bla bla
}


Make SURE you ALWAYS know the types of KEY and DATA in each Skip. Notice my comment when declaring skpProjItems. DXL will let you retrieve the wrong type, but aborts and diagnostic errors are sure to follow.

 

 

 

  • Louie